﻿@using CarCareTracker.Helper
@inject IConfigHelper config
@inject ITranslationHelper translator
@model InspectionRecordInput
@{
    var isNew = Model.Id == 0;
    var userConfig = config.GetUserConfig(User);
    var userLanguage = userConfig.UserLanguage;
}
<div class="modal-header">
    <h5 class="modal-title">@(isNew? translator.Translate(userLanguage, "Add New Inspection Record Template") : translator.Translate(userLanguage, "Edit Inspection Record Template"))<small style="display:none; @(isNew ? "" : "cursor:pointer;")" class="cached-banner ms-2 text-warning" onclick='@(isNew ? "" : $"showEditInspectionRecordTemplateModal({Model.Id}, true)")'>@translator.Translate(userLanguage, "Unsaved Changes")</small></h5>
    <button type="button" class="btn-close" onclick="hideInspectionRecordTemplateModal()" aria-label="Close"></button>
</div>
<div class="modal-body" onkeydown="handleEnter(this)">
    <form>
        <div class="form-group">
            <div class="row">
                <div class="col-12">
                    <input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;">
                    <label for="inspectionRecordDescription">@translator.Translate(userLanguage, "Description")</label>
                    <input type="text" id="inspectionRecordDescription" class="form-control" placeholder="@translator.Translate(userLanguage, "Description of Inspection")" value="@Model.Description">
                    <div class="row">
                        <div class="col-12">
                            <a onclick="showRecurringReminderSelector('inspectionRecordDescription', 'inspectionRecordNotes')" class="btn btn-link">@translator.Translate(userLanguage, "Select Reminder")</a>
                        </div>
                    </div>
                    <div id="inspectionRecordFields" style="overflow-y:auto;">
                        @foreach (InspectionRecordTemplateField inspectionRecordField in Model.Fields)
                        {
                            @await Html.PartialAsync("Inspection/_InspectionRecordField", inspectionRecordField)
                        }
                    </div>
                    <div class="d-grid p-2">
                        <button type="button" class="btn btn-warning" onclick="addInspectionRecordField()">@translator.Translate(userLanguage, "Add Field")</button>
                    </div>
                    <label for="inspectionRecordTemplateTag">@translator.Translate(userLanguage, "Tags(optional)")</label>
                    <select multiple class="form-select" id="inspectionRecordTemplateTag">
                        @foreach (string tag in Model.Tags)
                        {
                            <!option value="@tag">@tag</!option>
                        }
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    @if (!isNew)
    {
        <button type="button" class="btn btn-danger me-auto" onclick="deleteInspectionRecordTemplate(@Model.Id)">@translator.Translate(userLanguage, "Delete")</button>
    }
    <button type="button" class="btn btn-secondary" onclick="hideInspectionRecordTemplateModal()">@translator.Translate(userLanguage, "Cancel")</button>
    @if (isNew)
    {
        <button type="button" class="btn btn-primary" onclick="saveInspectionRecordTemplateToVehicle()">@translator.Translate(userLanguage, "Add")</button>
    }
    else
    {
        <div class="btn-group">
            <button type="button" class="btn btn-primary btn-md mt-1 mb-1" onclick="saveInspectionRecordTemplateToVehicle(true)">@translator.Translate(userLanguage, "Edit")</button>
            <button type="button" class="btn btn-md btn-primary btn-md mt-1 mb-1 dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
                <span class="visually-hidden">Toggle Dropdown</span>
            </button>
            <ul class="dropdown-menu">
                <li><a class="dropdown-item" href="#" onclick="duplicateInspectionRecordTemplate()">@translator.Translate(userLanguage, "Duplicate")</a></li>
                <li><a class="dropdown-item" href="#" onclick="duplicateInspectionRecordTemplateToVehicle()">@translator.Translate(userLanguage, "Duplicate To Vehicle")</a></li>
            </ul>
        </div>
    }
</div>
<script>
    var recurringReminderRecordId = [];
    function getInspectionRecordModelData() {
        return { id: @Model.Id}
    }
    @foreach (int reminderRecordId in Model.ReminderRecordId)
    {
                @:recurringReminderRecordId.push(@reminderRecordId);
    }
</script>